#include<bits/stdc++.h>
#define int long long 
#define mid ((l+r)>>1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=5e5+5,mod=1e9+7,Base=23;
inline int Mod(int x){return x>=mod?x-mod:x;}
int n,k,ans;
int a[N],f[N];
int st[N][21],LOG[N];
inline int ask(int l,int r){return max(st[l][LOG[r-l+1]],st[r-(1<<LOG[r-l+1])+1][LOG[r-l+1]]);}
void sol(int l,int r,int L,int R){
	if(l>r||L>R)return;
	if(l==r){for(int i=L;i<=R;i++)f[i]=min(f[i],f[max(l,i-k)]+ask(max(l,i-k)+1,i));return;}
	int MID=((L+R)>>1);
	int maxn=l-1;
	for(int i=max(l,MID-k);i<=r;i++)if(f[i]+ask(i+1,MID)<f[MID])maxn=i,f[MID]=f[i]+ask(i+1,MID);
	sol(l,maxn,L,MID-1),sol(maxn,r,MID+1,R);
}
void cdq(int l,int r){
	if(l>=r)return;
	cdq(l,mid),sol(l,mid,mid+1,min(r,mid+k)),cdq(mid+1,r);
	return;
}
signed main(){
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	read(n,k);
	for(int i=1;i<=n;i++)read(a[i]);
	if(n<=2000){
		for(int i=1;i<=n;i++)st[i][0]=a[i];
		for(int i=1;i<=20;i++)
			for(int j=1;j+(1<<i)-1<=n;j++)
				st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
		for(int i=0;(1<<i)<=n;i++)
			for(int j=(1<<i);j<(1<<(i+1));j++)
				LOG[j]=i;
		memset(f,0x3f,sizeof f);
		f[0]=0;
		for(int i=1;i<=n;i++)
			for(int j=max(0ll,i-k);j<i;j++)
				f[i]=min(f[i],f[j]+ask(j+1,i));
	}else{
		priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
		for(int i=1;i<=n;i++){
			q.push(make_pair(f[i-1],i-1));
			while(!q.empty()&&q.top().second<i-k)q.pop();
			f[i]=q.top().first+a[i];
		}
	}
	int sum=1;
	for(int i=n;i>=1;i--){
		ans=Mod(ans+1ll*f[i]*sum%mod);
		sum=1ll*sum*Base%mod;
	}
	write(ans);
	flush();
	return 0;
}
